﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
// Copyright (C) 2017 ZyCoder
// 版权所有。 
//
// 文件名：CacheManager
// 
// 创建者：名字 (zycoder)
// 时间：2018/2/25 17:04:36
//
// 版本：V1.0.0
// 网站: http://www.cnblogs.com/zycoder
//----------------------------------------------------------------*/
#endregion

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yunlive.Infrastructure.Cache
{
    /// <summary>
    /// 缓存管理类
    /// </summary>
    public class CacheManager : ICache
    {
        #region 缓存单利
        /// <summary>
        /// 线程锁
        /// </summary>
        private static object objLock = new object();
        /// <summary>
        /// 私有字段 缓存
        /// </summary>
        private static CacheManager _Instance;
        /// <summary>
        /// 缓存管理者单例
        /// </summary>
        public static CacheManager Instance
        {
            get
            {
                if (_Instance == null)
                {
                    lock (objLock)
                    {
                        if (_Instance == null)
                        {
                            _Instance = new CacheManager();
                        }
                    }
                }
                return _Instance;
            }
        }
        #endregion
        /// <summary>
        /// 缓存对象
        /// </summary>

        private ICache _iCache;
        /// <summary>
        /// 缓存类别
        /// </summary>
        private static string _cacheType = ConfigurationManager.AppSettings["CacheType"] ?? "RuntimeCache";

        public void Delete(string key)
        {
            _iCache.Delete(key);
        }

        public object Get(string key)
        {
            return _iCache.Get(key);
        }

        public void Put(string key, object value)
        {
            _iCache.Put(key, value);
        }

        public void Put(string key, object value, int expireMinutes)
        {
            _iCache.Put(key, value, expireMinutes);
        }
    }
}
